package com.dongnao.jack.spring.parse;

import java.io.Serializable;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.dongnao.jack.rmi.impl.RmiUtil;
import com.dongnao.jack.rmi.impl.SoaRemoteImpl;

/**
 * 
 * @ClassName: ProtocolConfig 
 * @Description: 客户端调用服务段使用的通讯协议 如http rmi等 
 * @author xuyp
 * @date 2018年4月17日 下午2:05:50 
 *
 */
public class ProtocolConfig implements Serializable, InitializingBean, ApplicationContextAware {

    private ApplicationContext applicationContext;

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = -1184984179261166701L;

    /**
     * 通讯协议的名称 如 http
     */
    private String name;

    /**
     * 通讯协议的主机地址
     */
    private String host;

    /**
     * 通讯协议的端口
     */
    private String port;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    @Override
    public String toString() {
        return "ProtocolConfig [name=" + name + ", host=" + host + ", port=" + port + "]";
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        if (name.equalsIgnoreCase("rmi")) {

            /* String[] serviceConfigNames = applicationContext.getBeanNamesForType(ServiceConfig.class);
            for (String serviceName : serviceConfigNames) {
                ServiceConfig bean = applicationContext.getBean(serviceName,ServiceConfig.class);
            }*/

            RmiUtil.startService(host, port, "soadubbormi", new SoaRemoteImpl());
        }

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;

    }

}
